/**
 * 
 */
package model;

import javax.cim.CIMInstance;

/**
 * This class represent an IPSecRule on the client side
 * @author alith
 */
public class IPSecRule extends CIMObject {

	private String name;
	private String source;
	private String destination;
	private String type;
	private String transport_type;
	private String spi;
	private String algorythm;
	private String key;
	private CIMServer server;

    public IPSecRule() {

    }
	
	/**
	 * Create a IPSecRule WITHOUT registering it on any server
	 * @param name the name of the IPSecRule, not stored on the server.
	 * @param source the source of the IPSecRule
	 * @param destination the destination of the IPSecRule
	 * @param type the type of the IPSecRule
	 * @param transport_type the transport_type of the IPSecRule
	 * @param spi the spi of the IPSecRule
	 * @param algorythm the algorithm of the IPSecRule
	 * @param key the key of the IPSecRule
	 * @param server the server in which the IPSecRule will eventually be stored
	 * @throws CIMBadArgument if any parameter is null or empty or not correct.
	 */
	public IPSecRule(String name,String source, String destination, String type, String transport_type, String spi, String algorythm, String key, CIMServer server)  throws CIMBadArgument{
	        this.name=name;
	        this.source = source;
	        this.destination = destination;
	        this.type = type;
	        this.transport_type = transport_type;
	        this.spi = spi;
	        this.algorythm = algorythm;
	        this.key = key;
	        this.server = server;
	}

    public IPSecRule(String name, String source, String destination, String type, String transport_type, String spi, String algorythm, String key) {
        this.name = name;
        this.source = source;
        this.destination = destination;
        this.type = type;
        this.transport_type = transport_type;
        this.spi = spi;
        this.algorythm = algorythm;
        this.key = key;
    }
	
    /**
     * Create an empty IPSecRule, only with the server on which it will eventually be stored.
     * @param server the server in which the IPSecRule will eventually be stored
     * @throws CIMBadArgument if any parameter is null or empty or not correct.
     */
	public IPSecRule(CIMServer server)  throws CIMBadArgument{
	    this.server = server;
	}

    /**
     * Create an IPSecRule with an CIMInstance (ie a result from a request on the server)
     * @param inst the CIMInstance of the IPSecRule to create
     * @param numero a number to identify this IPSecRule (to create an unique name)
     * @param server the server in which this new IPSecRule will eventually be stored.
     */
	public IPSecRule(CIMInstance inst, int numero, CIMServer server) {
    	this.name = "regle n°"+numero;//n'a aucun sens mais thomas le demande...
        this.source = (String) inst.getProperty("source").getValue();
        this.destination = (String) inst.getProperty("destination").getValue();
        this.type = (String) inst.getProperty("type").getValue();
        this.transport_type = (String) inst.getProperty("transport_type").getValue();
        this.spi = (String) inst.getProperty("spi").getValue();
        this.algorythm = (String) inst.getProperty("algo").getValue();
        this.key = (String) inst.getProperty("key").getValue();
        this.server = server;
		}

	/* (non-Javadoc)
	 * @see model.CIMObject#delete()
	 */
	@Override
	public void delete() throws Exception {
		server.remove(this);
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#modify()
	 */
	@Override
	public void modify() throws Exception {
		server.update(this);
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#register()
	 */
	@Override
	public void register() throws Exception {
		server.register(this);
	}
	
	/**
	 * getter to the name of the IPSecRule
	 * @return the name of the IPSecRule
	 */
	public String getName() {
		return name;
	}

	/**
	 * setter to the name of the IPSecRule
	 * @param name the name of the IPSecRule
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * getter to the source of the IPSecRule
	 * @return the source of the IPSecRule
	 */
	public String getSource() {
		return source;
	}

	/**
	 * setter to the source of the IPSecRule
	 * @param source the source of the IPSecRule
	 */
	public void setSource(String source) {
		this.source = source;
	}

	/**
	 * getter to the destination of the IPSecRule
	 * @return the destination of the IPSecRule
	 */
	public String getDestination() {
		return destination;
	}
	
	/**
	 * setter to the destination of the IPSecRule
	 * @param destination the destination of the IPSecRule
	 */
	public void setDestination(String destination) {
		this.destination = destination;
	}

	/**
	 * getter to the type of the IPSecRule
	 * @return the type of the IPSecRule
	 */
	public String getType() {
		return type;
	}
	
	/**
	 * setter to the type of the IPSecRule
	 * @param type the type of the IPSecRule
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * getter to the transport_type of the IPSecRule
	 * @return the transport_type of the IPSecRule
	 */
	public String getTransport_type() {
		return transport_type;
	}
	
	/**
	 * setter to the transport_type of the IPSecRule
	 * @param transportType the transport_type of the IPSecRule
	 */
	public void setTransport_type(String transportType) {
		transport_type = transportType;
	}

	/**
	 * getter to the spi of the IPSecRule
	 * @return the spi of the IPSecRule
	 */
	public String getSpi() {
		return spi;
	}
	
	/**
	 * setter to the spi of the IPSecRule
	 * @param spi the spi of the IPSecRule
	 */
	public void setSpi(String spi) {
		this.spi = spi;
	}

	/**
	 * getter to the algorythm of the IPSecRule
	 * @return the algorythm of the IPSecRule
	 */
	public String getAlgorythm() {
		return algorythm;
	}
	
	/**
	 * setter to the algorythm of the IPSecRule
	 * @param algorythm the algorythm of the IPSecRule
	 */
	public void setAlgorythm(String algorythm) {
		this.algorythm = algorythm;
	}

	/**
	 * getter to the key of the IPSecRule
	 * @return the key of the IPSecRule
	 */
	public String getKey() {
		return key;
	}
	
	/**
	 * setter to the key of the IPSecRule
	 * @param key the key of the IPSecRule
	 */
	public void setKey(String key) {
		this.key = key;
	}
	
	/* (non-Javadoc)
	 * @see object#toString()
	 */
	@Override
	public String toString() {
		return "regle:"+name+" source:"+source+" destination:"+destination+" type="+type+" transport_type="+transport_type+" spi="+spi+" algorythm="+algorythm+" key="+key;
	}
}
